home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr29 / extnp100.zip / EXTRNETP.C next >
C/C++ Source or Header  |  1995-02-12  |  25KB  |  701 lines

  1. /******************************************************************************
  2. *******************************************************************************
  3. **                                                                           **
  4. **  EXTRNETP                                                                 **
  5. **  Copyright (c) Bob Swift, 1995.  All rights reserved.                     **
  6. **  Compiled with the Watcom C/C++ Compiler                                  **
  7. **                                                                           **
  8. ******************************************************************************/
  9. #define PRG_TITLE   "EXTRNETP"              //         Program Name          **
  10. #define PRG_DATES   "1995"                  //         Copyright Date        **
  11. #define PRG_VERSION "1.00"                  //         Version Number        **
  12. #define PRG_AUTHOR  "Bob Swift"             //         Author's Name         **
  13. /******************************************************************************
  14. **                                                                           **
  15. **  This program is designed to read an input nodelist file and extract      **
  16. **  selected Networks, Regions and/or Zones.  The extracted portions of      **
  17. **  the nodelist are stored in a file specified on the command line.         **
  18. **                                                                           **
  19. **  The format for using this program is as follows:                         **
  20. **                                                                           **
  21. **                                                                           **
  22. **       EXTRNETP <srcfile> <destfile> [I] <net1> <net2>...<net20>           **
  23. **                                                                           **
  24. **  where <srcfile>    is the name of the nodelist file to be read           **
  25. **        <destfile>   is the name of the output file created                **
  26. **        [I]          optionally include all Zone entries                   **
  27. **        <net..>      are the numbers of the Net/Region/Zones to be         **
  28. **                     extracted and may include zone specifiers for Nets    **
  29. **                     and Regions (the program is presently set to handle   **
  30. **                     20 numbers).  These numbers may be preceded by a N,   **
  31. **                     R or Z in order to extract the entire Net, Region     **
  32. **                     or Zone.  Examples are: 123 N342 n2:201 r17 Z1        **
  33. **                                                                           **
  34. **                                                                           **
  35. **  The nodelist may be specified with a full drive and path.  The           **
  36. **  destination file must not have a drive or path specified.  It will be    **
  37. **  output to the current directory.                                         **
  38. **                                                                           **
  39. **  The program will display a VERY brief set of instructions if it is       **
  40. **  called without any arguments or if it encounters an error.  The          **
  41. **  following is a list of the error codes returned by the program:          **
  42. **                                                                           **
  43. **                 0 - No errors.  Normal termination.                       **
  44. **                 1 - Bad or missing command line argument.                 **
  45. **                 2 - Unable to open the input file.                        **
  46. **                 3 - Unable to open the output file.                       **
  47. **                 4 - Problem writing to output file.                       **
  48. **                 5 - Problem closing input file.                           **
  49. **                 6 - Problem closing output file.                          **
  50. **                 7 - Unable to open configuration file.                    **
  51. **                 8 - Unable to create backup file.                         **
  52. **                                                                           **
  53. **  When an error is encountered, the program will exit immediately and      **
  54. **  will attempt to properly close all files.                                **
  55. **                                                                           **
  56. *******************************************************************************
  57. ******************************************************************************/
  58.  
  59. #include <stdio.h>
  60. #include <string.h>
  61. #include <time.h>
  62. #include <mem.h>
  63.  
  64.     /* the CRC polynomial. This is used by XMODEM (almost CCITT).
  65.      * If you change P, you must change crctab[]'s initial value to what is
  66.      * printed by initcrctab()
  67.      */
  68. #define   P    0x1021
  69.  
  70.     /* number of bits in CRC: don't change it. */
  71. #define W 16
  72.  
  73.     /* this the number of bits per char: don't change it. */
  74. #define B 8
  75.  
  76. static unsigned short crctab[1<<B] = { /* as calculated by initcrctab() */
  77.     0x0000,  0x1021,  0x2042,  0x3063,  0x4084,  0x50a5,  0x60c6,  0x70e7,
  78.     0x8108,  0x9129,  0xa14a,  0xb16b,  0xc18c,  0xd1ad,  0xe1ce,  0xf1ef,
  79.     0x1231,  0x0210,  0x3273,  0x2252,  0x52b5,  0x4294,  0x72f7,  0x62d6,
  80.     0x9339,  0x8318,  0xb37b,  0xa35a,  0xd3bd,  0xc39c,  0xf3ff,  0xe3de,
  81.     0x2462,  0x3443,  0x0420,  0x1401,  0x64e6,  0x74c7,  0x44a4,  0x5485,
  82.     0xa56a,  0xb54b,  0x8528,  0x9509,  0xe5ee,  0xf5cf,  0xc5ac,  0xd58d,
  83.     0x3653,  0x2672,  0x1611,  0x0630,  0x76d7,  0x66f6,  0x5695,  0x46b4,
  84.     0xb75b,  0xa77a,  0x9719,  0x8738,  0xf7df,  0xe7fe,  0xd79d,  0xc7bc,
  85.     0x48c4,  0x58e5,  0x6886,  0x78a7,  0x0840,  0x1861,  0x2802,  0x3823,
  86.     0xc9cc,  0xd9ed,  0xe98e,  0xf9af,  0x8948,  0x9969,  0xa90a,  0xb92b,
  87.     0x5af5,  0x4ad4,  0x7ab7,  0x6a96,  0x1a71,  0x0a50,  0x3a33,  0x2a12,
  88.     0xdbfd,  0xcbdc,  0xfbbf,  0xeb9e,  0x9b79,  0x8b58,  0xbb3b,  0xab1a,
  89.     0x6ca6,  0x7c87,  0x4ce4,  0x5cc5,  0x2c22,  0x3c03,  0x0c60,  0x1c41,
  90.     0xedae,  0xfd8f,  0xcdec,  0xddcd,  0xad2a,  0xbd0b,  0x8d68,  0x9d49,
  91.     0x7e97,  0x6eb6,  0x5ed5,  0x4ef4,  0x3e13,  0x2e32,  0x1e51,  0x0e70,
  92.     0xff9f,  0xefbe,  0xdfdd,  0xcffc,  0xbf1b,  0xaf3a,  0x9f59,  0x8f78,
  93.     0x9188,  0x81a9,  0xb1ca,  0xa1eb,  0xd10c,  0xc12d,  0xf14e,  0xe16f,
  94.     0x1080,  0x00a1,  0x30c2,  0x20e3,  0x5004,  0x4025,  0x7046,  0x6067,
  95.     0x83b9,  0x9398,  0xa3fb,  0xb3da,  0xc33d,  0xd31c,  0xe37f,  0xf35e,
  96.     0x02b1,  0x1290,  0x22f3,  0x32d2,  0x4235,  0x5214,  0x6277,  0x7256,
  97.     0xb5ea,  0xa5cb,  0x95a8,  0x8589,  0xf56e,  0xe54f,  0xd52c,  0xc50d,
  98.     0x34e2,  0x24c3,  0x14a0,  0x0481,  0x7466,  0x6447,  0x5424,  0x4405,
  99.     0xa7db,  0xb7fa,  0x8799,  0x97b8,  0xe75f,  0xf77e,  0xc71d,  0xd73c,
  100.     0x26d3,  0x36f2,  0x0691,  0x16b0,  0x6657,  0x7676,  0x4615,  0x5634,
  101.     0xd94c,  0xc96d,  0xf90e,  0xe92f,  0x99c8,  0x89e9,  0xb98a,  0xa9ab,
  102.     0x5844,  0x4865,  0x7806,  0x6827,  0x18c0,  0x08e1,  0x3882,  0x28a3,
  103.     0xcb7d,  0xdb5c,  0xeb3f,  0xfb1e,  0x8bf9,  0x9bd8,  0xabbb,  0xbb9a,
  104.     0x4a75,  0x5a54,  0x6a37,  0x7a16,  0x0af1,  0x1ad0,  0x2ab3,  0x3a92,
  105.     0xfd2e,  0xed0f,  0xdd6c,  0xcd4d,  0xbdaa,  0xad8b,  0x9de8,  0x8dc9,
  106.     0x7c26,  0x6c07,  0x5c64,  0x4c45,  0x3ca2,  0x2c83,  0x1ce0,  0x0cc1,
  107.     0xef1f,  0xff3e,  0xcf5d,  0xdf7c,  0xaf9b,  0xbfba,  0x8fd9,  0x9ff8,
  108.     0x6e17,  0x7e36,  0x4e55,  0x5e74,  0x2e93,  0x3eb2,  0x0ed1,  0x1ef0
  109.     };
  110.  
  111. short int cfputs(char *s,FILE *stream);
  112. unsigned short updcrc(unsigned short icrc,unsigned char *icp,unsigned short icnt);
  113. void helpscrn(short int ernum);
  114. void add_period(char filename[]);
  115. void build_bak_name(char filename[]);
  116. short int is_in_dir(char *filename);
  117. short int del_backup(char *filename);
  118. short int linetest(char *linetst1, char *inline);
  119. short int make_backup(char *srcfile, char *destfile);
  120. unsigned short crc;
  121.  
  122. /*****************************************************************************/
  123.  
  124. void main(int argc, char *argv[])
  125. {
  126. char flnames[3][40];
  127. char inline[358];
  128. char linetst1[20];
  129. char lintest[21][20];
  130. char zontest[21][10];
  131. char linshow[21][40];
  132. short int  lineflag[21];
  133. char semi[20];
  134. char temp[20];
  135. char curzone[10];
  136. time_t t;
  137. fpos_t filepos;
  138. char *pntr;
  139. short int i,j;
  140. short int sub1;
  141. short int count;
  142. short int flag;
  143. short int zoneflag;
  144. FILE *in_file,*out_file;
  145.  
  146. strcpy(curzone,"0");
  147. zoneflag = 0;
  148. t = time(NULL);
  149.  
  150. printf("\n\n%s Version %s\n",PRG_TITLE,PRG_VERSION);
  151. printf("Copyright (c) %s, %s.  All Rights Reserved.\n",PRG_AUTHOR,PRG_DATES);
  152.  
  153. if (argc < 4 || argc > 14) helpscrn(1);
  154. strcpy(flnames[1],strupr(argv[1]));             /*  Input File  */
  155. strcpy(flnames[2],strupr(argv[2]));             /* Output File  */
  156. strcpy(flnames[3],strupr(argv[2]));             /* Backup File  */
  157.  
  158. if (is_in_dir(flnames[2]) == 1)
  159.     helpscrn(7);
  160.  
  161. add_period(flnames[3]);
  162. build_bak_name(flnames[3]);
  163.  
  164. if (del_backup(flnames[3]) == 1)
  165.     helpscrn(8);
  166.  
  167. /*  Exit if output file has an extension of BAK  */
  168. if (strcmp(flnames[2],flnames[3])==0)
  169.    helpscrn(8);
  170.  
  171. if (make_backup(flnames[2],flnames[3]) == 1)
  172.     helpscrn(8);
  173.  
  174. in_file=fopen(flnames[1],"rt");
  175. if (in_file == NULL)
  176.     helpscrn(2);
  177.  
  178. if ((out_file=fopen(flnames[2],"wt")) == NULL)
  179.     helpscrn(3);
  180.  
  181. count = 3;
  182. sub1 = 0;
  183. while (count < argc)      /*  Set Up Search Strings  */
  184.   {
  185.     strcpy(semi,argv[count]);
  186.     switch(semi[0])
  187.       {
  188.       case 'i': ;
  189.       case 'I': sub1++;
  190.                 strcpy(lintest[sub1],"I,");
  191.                 strcpy(zontest[sub1],"0");
  192.                 strcpy(linshow[sub1],"Include all ZONE entries.");
  193.                 lineflag[sub1] = 'I';
  194.                 zoneflag = 1;
  195.                 break;
  196.       case 'n': ;
  197.       case 'N': sub1++;
  198.                 strcpy(lintest[sub1],"Host,");
  199.                 strcpy(zontest[sub1],"0");
  200.                 strcpy(linshow[sub1],"Net ");
  201.                 lineflag[sub1] = 'N';
  202.                 i = 0;
  203.                 j = 1;
  204.                 strcpy(temp,"0");
  205.                 while (semi[j] != '\0')
  206.                   {
  207.                   temp[i] = semi[j];
  208.                   i++;
  209.                   j++;
  210.                   temp[i] = '\0';
  211.                   if (semi[j] == ':')
  212.                     {
  213.                     j++;
  214.                     strcpy(zontest[sub1],temp);
  215.                     i = 0;
  216.                     strcpy(temp,"0");
  217.                     }
  218.                   }
  219.                 strcat(lintest[sub1],temp);
  220.                 strcat(lintest[sub1],",");
  221.                 strcat(linshow[sub1],temp);
  222.                 if (zontest[sub1][0] != '0')
  223.                   {
  224.                   strcat(linshow[sub1],"  (Zone ");
  225.                   strcat(linshow[sub1],zontest[sub1]);
  226.                   strcat(linshow[sub1],")");
  227.                   }
  228.                 break;
  229.       case 'r': ;
  230.       case 'R': sub1++;
  231.                 strcpy(lintest[sub1],"Region,");
  232.                 strcpy(zontest[sub1],"0");
  233.                 strcpy(linshow[sub1],"Region ");
  234.                 lineflag[sub1] = 'R';
  235.                 i = 0;
  236.                 j = 1;
  237.                 strcpy(temp,"0");
  238.                 while (semi[j] != '\0')
  239.                   {
  240.                   temp[i] = semi[j];
  241.                   i++;
  242.                   j++;
  243.                   temp[i] = '\0';
  244.                   if (semi[j] == ':')
  245.                     {
  246.                     j++;
  247.                     strcpy(zontest[sub1],temp);
  248.                     i = 0;
  249.                     strcpy(temp,"0");
  250.                     }
  251.                   }
  252.                 strcat(lintest[sub1],temp);
  253.                 strcat(lintest[sub1],",");
  254.                 strcat(linshow[sub1],temp);
  255.                 if (zontest[sub1][0] != '0')
  256.                   {
  257.                   strcat(linshow[sub1],"  (Zone ");
  258.                   strcat(linshow[sub1],zontest[sub1]);
  259.                   strcat(linshow[sub1],")");
  260.                   }
  261.                 break;
  262.       case 'z': ;
  263.       case 'Z': sub1++;
  264.                 strcpy(lintest[sub1],"Zone,");
  265.                 strcpy(zontest[sub1],"0");
  266.                 strcpy(linshow[sub1],"Zone ");
  267.                 lineflag[sub1] = 'Z';
  268.                 i = 5;
  269.                 j = 1;
  270.                 strcpy(temp,"0");
  271.                 while (semi[j] != '\0')
  272.                   {
  273.                   lintest[sub1][i] = semi[j];
  274.                   linshow[sub1][i] = semi[j];
  275.                   i++;
  276.                   j++;
  277.                   }
  278.                 lintest[sub1][i] = '\0';
  279.                 linshow[sub1][i] = '\0';
  280.                 strcat(lintest[sub1],",");
  281.                 break;
  282.       default:
  283.           {
  284.             sub1++;
  285.             lineflag[sub1] = 'A';
  286.             strcpy(lintest[sub1],"Zone,");
  287.                 strcpy(zontest[sub1],"0");
  288.             strcpy(linshow[sub1],"Zone ");
  289.                 i = 0;
  290.                 j = 0;
  291.                 strcpy(temp,"0");
  292.                 while (semi[j] != '\0')
  293.                   {
  294.                   temp[i] = semi[j];
  295.                   i++;
  296.                   j++;
  297.                   temp[i] = '\0';
  298.                   if (semi[j] == ':')
  299.                     {
  300.                     j++;
  301.                     strcpy(zontest[sub1],temp);
  302.                     i = 0;
  303.                     strcpy(temp,"0");
  304.                     }
  305.                   }
  306.                 strcat(lintest[sub1],temp);
  307.                 strcat(lintest[sub1],",");
  308.                 strcat(linshow[sub1],temp);
  309.             sub1++;
  310.             lineflag[sub1] = 'A';
  311.             strcpy(lintest[sub1],"Region,");
  312.                 strcpy(zontest[sub1],zontest[sub1-1]);
  313.                 strcpy(zontest[sub1-1],"0");
  314.             strcpy(linshow[sub1],"Region ");
  315.                 strcat(lintest[sub1],temp);
  316.                 strcat(lintest[sub1],",");
  317.                 strcat(linshow[sub1],temp);
  318.                 if (zontest[sub1][0] != '0')
  319.                   {
  320.                   strcat(linshow[sub1],"  (Zone ");
  321.                   strcat(linshow[sub1],zontest[sub1]);
  322.                   strcat(linshow[sub1],")");
  323.                   }
  324.             sub1++;
  325.             lineflag[sub1] = 'A';
  326.             strcpy(lintest[sub1],"Host,");
  327.                 strcpy(zontest[sub1],zontest[sub1-1]);
  328.             strcpy(linshow[sub1],"Net ");
  329.                 strcat(lintest[sub1],temp);
  330.                 strcat(lintest[sub1],",");
  331.                 strcat(linshow[sub1],temp);
  332.                 if (zontest[sub1][0] != '0')
  333.                   {
  334.                   strcat(linshow[sub1],"  (Zone ");
  335.                   strcat(linshow[sub1],zontest[sub1]);
  336.                   strcat(linshow[sub1],")");
  337.                   }
  338.           }
  339.       }
  340.   count++;
  341.   }
  342. printf("Extracting:   ");    /*  Echo Input To User  */
  343. for (count=1;count<=sub1;count++)
  344. {
  345.   printf("%s\n              ",linshow[count]);
  346. }
  347. printf("\n");
  348.  
  349. /*  Get first line of source nodelist file  */
  350. /*  and print header to output file.        */
  351. if (fgets(inline,256,in_file) == NULL)
  352.   {
  353.   if (fputs(";A Extracted Nodelist Segment : 00000\n",out_file) == EOF) helpscrn(4);
  354.   }
  355. else
  356.   {
  357.   if (fputs(";A Extracted ",out_file) == EOF) helpscrn(4);
  358.   if (fputs(inline+3,out_file) == EOF) helpscrn(4);
  359.   }
  360. crc = 0;
  361. if (fgetpos(out_file,&filepos) != 0) helpscrn(4);
  362. filepos = filepos - 7L;
  363.  
  364. /*  Print extraction info to output file  */
  365. if (cfputs(";A \n;A Extracted with ",out_file) == EOF) helpscrn(4);
  366. if (cfputs(PRG_TITLE,out_file) == EOF) helpscrn(4);
  367. if (cfputs(" Version ",out_file) == EOF) helpscrn(4);
  368. if (cfputs(PRG_VERSION,out_file) == EOF) helpscrn(4);
  369. if (cfputs("\n;A ",out_file) == EOF) helpscrn(4);
  370. if (cfputs("Copyright (c) ",out_file) == EOF) helpscrn(4);
  371. if (cfputs(PRG_AUTHOR,out_file) == EOF) helpscrn(4);
  372. if (cfputs(", ",out_file) == EOF) helpscrn(4);
  373. if (cfputs(PRG_DATES,out_file) == EOF) helpscrn(4);
  374. if (cfputs(".  All Rights Reserved.",out_file) == EOF) helpscrn(4);
  375. if (cfputs("\n;A \n;A Extracted from ",out_file) == EOF) helpscrn(4);
  376. if (cfputs(flnames[1],out_file) == EOF) helpscrn(4);
  377. if (cfputs(" on ",out_file) == EOF) helpscrn(4);
  378. if (cfputs(ctime(&t),out_file) == EOF) helpscrn(4);
  379. if (cfputs(";A \n;A Extracting:     ",out_file) == EOF) helpscrn(4);
  380. if (cfputs(linshow[1],out_file) == EOF) helpscrn(4);
  381. for (count=2;count<=sub1;count++)
  382.   {
  383.   if(cfputs("\n;A                 ",out_file) == EOF) helpscrn(4);
  384.   if(cfputs(linshow[count],out_file) == EOF) helpscrn(4);
  385.   }
  386. if (cfputs("\n;A \n;\n",out_file) == EOF) helpscrn(4);
  387.  
  388. /*  Initialize  */
  389. count = sub1;
  390. flag = 1;
  391. j = 0;
  392.  
  393. /*  Get line from source file  */
  394. while (fgets(inline,256,in_file) != NULL)
  395.   {
  396.   if (inline[0] == 'Z')
  397.     {
  398.       i = 0;
  399.       for (sub1=5;(inline[sub1] != ',') && (sub1 < strlen(inline));sub1++)
  400.         {
  401.           curzone[i] = inline[sub1];
  402.           i++;
  403.           curzone[i] = '\0';
  404.         }
  405.     }
  406.     strcpy(semi,";");
  407.     i = linetest(semi,inline);
  408.     strcpy(semi,";\n");
  409.     if ((linetest(semi,inline) == 1 && flag == 0) || i == 0)
  410.     {
  411.  
  412.       if (flag == 0)
  413.       {
  414.         strcpy(semi,"Host");
  415.         i = linetest(semi,inline);
  416.         if (i == 1 && (j == 'N' || j == 'A')) flag = 1;
  417.         if (flag == 1) if (cfputs(";\n",out_file) == EOF) helpscrn(4);
  418.       }
  419.  
  420.       if (flag == 0)
  421.       {
  422.         strcpy(semi,"Region");
  423.         i = linetest(semi,inline);
  424.         if (i == 1 && (j == 'N' || j == 'R' || j == 'A')) flag = 1;
  425.         if (flag == 1) if (cfputs(";\n",out_file) == EOF) helpscrn(4);
  426.       }
  427.  
  428.  
  429.       if (flag == 0)
  430.       {
  431.         strcpy(semi,"Zone");
  432.         flag = linetest(semi,inline);
  433.         if (flag == 1) if (cfputs(";\n",out_file) == EOF) helpscrn(4);
  434.       }
  435.  
  436.       if (flag == 0)
  437.       {
  438.         if (cfputs(inline,out_file) == EOF)
  439.            helpscrn(4);
  440.       }
  441.  
  442.       if (flag == 1)
  443.       {
  444.  
  445.         /*  Cycle through the search patterns  */
  446.         for (sub1=1;sub1<=count && linetest(lintest[sub1],inline)==0;sub1++)
  447.         {
  448.             /*  Null Line  */
  449.         }
  450.  
  451.         if (sub1 <= count) i = linetest(curzone,zontest[sub1]);
  452.         if ((sub1 <= count) && ((zontest[sub1][0] == '0') || (i == 1)))
  453.         {
  454.           if (cfputs(inline,out_file) == EOF)
  455.              helpscrn(4);
  456.           flag = 0;
  457.           j = lineflag[sub1];
  458.         }
  459.       }
  460.  
  461.       if (flag == 1)
  462.       {
  463.  
  464.         /*  Check if Zone and print if all Zones selected  */
  465.         strcpy(semi,"Zone");
  466.         if (linetest(semi,inline) == 1)
  467.         {
  468.           i = 0;
  469.           for (sub1=1;sub1<=count;sub1++)
  470.           {
  471.             if (linetest(zontest[sub1],curzone) == 1) i = 1;
  472.           }
  473.           if ((i == 1) || (zoneflag == 1))
  474.           {
  475.             if (cfputs(inline,out_file) == EOF) helpscrn(4);
  476.             if (cfputs(";\n",out_file) == EOF) helpscrn(4);
  477.           }
  478.         }
  479.  
  480.       }
  481.     }
  482.   if (inline[0] == 'Z' || inline[0] == 'R' || (inline[0] == 'H' && inline[2] == 's'))
  483.     {
  484.       inline[strlen(inline)-1] = '\0';
  485.       i = 0;
  486.       for (sub1=0;sub1<=strlen(inline) && i<3;sub1++)
  487.         {
  488.           if (inline[sub1] == ',')
  489.             {
  490.               i++;
  491.               if (i >= 3)
  492.                 inline[sub1] = '\0';
  493.               if (i == 1)
  494.                 inline[sub1] = ' ';
  495.             }
  496.           if (inline[sub1] == '_')
  497.             inline[sub1] = ' ';
  498.         }
  499.       memset(inline+strlen(inline),' ',79);
  500.       inline[79] = '\0';
  501.       printf("%s",inline);
  502.       if (inline[0] == 'Z')
  503.         printf("\n");
  504.       else
  505.         printf("\r");
  506.     }
  507.   }
  508. if (cfputs(";S End of extracted file.\n;S \n",out_file) == EOF) helpscrn(4);
  509.  
  510. /*  Close the source file  */
  511. if (fclose(in_file) != 0)
  512.    helpscrn(5);
  513.  
  514. /*  Update the CRC value in the output file  */
  515. if (fsetpos(out_file,&filepos) != 0) helpscrn(4);
  516. fprintf(out_file,"%05u",crc);
  517.  
  518. /*  Close the destination file  */
  519. if (fclose(out_file) != 0)
  520.    helpscrn(6);
  521.  
  522. /*  Thank the user and exit gracefully  */
  523. memset(inline,' ',80);
  524. inline[79] = '\0';
  525. printf("%s",inline);
  526. printf("\nExtraction complete.  Thank-you for using %s.\n\n",PRG_TITLE);
  527. exit(0);
  528. }
  529.  
  530. /*****************************************************************************/
  531.  
  532. short int cfputs(char *s,FILE *stream)
  533. {
  534. char string[256];
  535. short int i,j;
  536.  
  537. i = 0;
  538. j = 0;
  539. string[0] = '\0';
  540. while (s[j] != '\0')
  541.   {
  542.   if (s[j] == '\n')
  543.     {
  544.     string[i] = 13;
  545.     i++;
  546.     string[i] = 10;
  547.     i++;
  548.     string[i] = '\0';
  549.     }
  550.   else
  551.     {
  552.     string[i] = s[j];
  553.     i++;
  554.     string[i] = '\0';
  555.     }
  556.   j++;
  557. }
  558. crc = updcrc(crc,string,i);
  559. return (fputs(s,stream));
  560. }
  561.  
  562. /*****************************************************************************/
  563.  
  564. unsigned short updcrc(unsigned short icrc,unsigned char *icp,unsigned short int icnt)
  565. {
  566. register unsigned short crc1 = icrc;
  567. register unsigned char *cp = icp;
  568. register unsigned int cnt = icnt;
  569.  
  570. while (cnt--)  crc1 = (crc1<<B) ^ crctab[(crc1>>(W-B)) ^ *cp++];
  571.  
  572. return(crc1);
  573. }
  574.  
  575. /*****************************************************************************/
  576.  
  577. short int is_in_dir(char *filename)
  578. /*  Check if input file in current directory  */
  579. {
  580. if (strchr(filename,'\\')!=NULL || strchr(filename,':')!=NULL)
  581.    return(1);
  582.  else
  583.    return(0);
  584. }
  585.  
  586. /*****************************************************************************/
  587.  
  588. void add_period(char filename[])
  589. /*  If input file has no extension finish it with a period  */
  590. {
  591. if (strchr(filename,'.')==NULL)
  592.    strcat(filename,".");
  593. }
  594.  
  595. /*****************************************************************************/
  596.  
  597. void build_bak_name(char filename[])
  598. /*  Build file name for backup file  */
  599. {
  600. short int flag;
  601. for (flag=0;filename[flag]!='.';flag++)
  602.    {
  603.    /*  NULL Line  */
  604.    }
  605. filename[flag] = '\0';
  606. strcat(filename,".BAK");
  607. }
  608.  
  609. /*****************************************************************************/
  610.  
  611. short int del_backup(char *filename)
  612. /*  Check for existing backup file and delete  */
  613. {
  614. FILE *tempfile;
  615. tempfile=fopen(filename,"r");
  616. fclose(tempfile);
  617. if (tempfile != NULL)
  618.    {
  619.    if (unlink(filename) != 0)
  620.       return(1);
  621.    }
  622. return(0);
  623. }
  624.  
  625. /*****************************************************************************/
  626.  
  627. short int make_backup(char *srcfile, char *destfile)
  628. /*  Rename source file to destination file  */
  629. {
  630. FILE *tempfile;
  631. tempfile=fopen(srcfile,"r");
  632. fclose(tempfile);
  633. if (tempfile != NULL)
  634.    {
  635.    if (rename(srcfile,destfile) != 0)
  636.       return(1);
  637.    }
  638. return(0);
  639. }
  640.  
  641. /*****************************************************************************/
  642.  
  643. short int linetest(char *linetst1, char *inline)
  644. /*  This is the routine that actually checks for a match  */
  645. {
  646. short int j;
  647. for ( j=0; linetst1[j] == inline[j]; j++ )
  648.     if (linetst1[j+1] == '\0') return(1);
  649. return(0);
  650. }
  651.  
  652. /*****************************************************************************/
  653.  
  654. void helpscrn(short int ernum)
  655. /*  Here are the error messages and VERY brief instructions  */
  656. {
  657. cprintf("\n");
  658. switch (ernum) {
  659.  
  660. case  1 : printf("     **  Bad or missing command line argument  **\n\n");
  661.           break;
  662.  
  663. case  2 : printf("     **  Unable to open input file  **\n\n");
  664.           break;
  665.  
  666. case  3 : printf("     **  Unable to open output file  **\n\n");
  667.           break;
  668.  
  669. case  4 : printf("     **  Problem writing to output file  **\n\n");
  670.           break;
  671.  
  672. case  5 : printf("     **  Problem closing input file  **\n\n");
  673.           break;
  674.  
  675. case  6 : printf("     **  Problem closing output file  **\n\n");
  676.           break;
  677.  
  678. case  7 : printf("     **  Output file not in current directory  **\n\n");
  679.           break;
  680.  
  681. case  8 : printf("     **  Unable to create backup file  **\n\n");
  682.           break;
  683.     }
  684. printf("This program is designed to read an input nodelist file and extract");
  685. printf("\nselected Networks, Regions and/or Zones.  The extracted portions ");
  686. printf("of\nthe nodelist are stored in a file specified on the command line");
  687. printf(".\n\nThe format for using this program is as follows:\n\n");
  688. printf("     %s <srcfile> <destfile> [I] <net1> <net2>...<net20>\n\n",PRG_TITLE);
  689. printf("where <srcfile>    is the name of the nodelist file to be read\n");
  690. printf("      <destfile>   is the name of the output file created\n");
  691. printf("      [I]          optionally include all Zone entries\n");
  692. printf("      <net..>      are the numbers of the Net/Region/Zones to be extracted\n");
  693. printf("                   and may include zone specifiers for Nets and Regions\n");
  694. printf("                   (the program is presently set to handle 20 numbers).\n");
  695. printf("                   These numbers may be preceded by a N, R or Z in order\n");
  696. printf("                   to extract the entire Net, Region or Zone.  Examples\n");
  697. printf("                   are: 123 N342 n2:201 r17 Z1\n");
  698. exit(ernum);
  699. }
  700.  
  701.